package net.xumf.web.controller.system.dict;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.xumf.domain.master.Dict;
import net.xumf.service.master.DictService;
import net.xumf.support.annotation.RequiresPermissions;
import net.xumf.support.enums.Logical;
import net.xumf.support.model.ResponseResult;
import net.xumf.support.model.dto.PageDTO;
import net.xumf.web.controller.common.BaseControllerImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
@Api(value = "字典管理", description = "字典管理")
@RequestMapping("system/dict")
public class DictController extends BaseControllerImpl<PageDTO, DictService, Dict, Integer> {

    /**
     * 获取所有列表
     *
     * @return {@link List}
     */
    @ApiOperation(value = "通过父id获取子字典")
    @ApiImplicitParam(name = "parentId", value = "父字典id", required = true, dataTypeClass = Integer.class, paramType = "path", example = "0为顶级")
    @GetMapping("/get/{parentId}")
    @RequiresPermissions(value = {"sys.dict:view", "sys.dict:*"}, logical = Logical.OR)
    public List<Dict> getAll(@PathVariable Integer parentId) {
        return service.getByParentId(parentId);
    }

    @Override
    @RequiresPermissions(value = {"sys.dict:view", "sys.dict:*"}, logical = Logical.OR)
    public ResponseResult get(@PathVariable Integer id) {
        return super.get(id);
    }

    @Override
    @RequiresPermissions(value = {"sys.dict:add", "sys.dict:*"}, logical = Logical.OR)
    public ResponseResult add(Dict dict) {
        return super.add(dict);
    }

    @Override
    @RequiresPermissions(value = {"sys.dict:delete", "sys.dict:*"}, logical = Logical.OR)
    public ResponseResult del(@PathVariable Integer id) {
        return super.del(id);
    }

    @Override
    @RequiresPermissions(value = {"sys.dict:edit", "sys.dict:*"}, logical = Logical.OR)
    public ResponseResult edit(@PathVariable Integer id, Dict p) {
        return super.edit(id, p);
    }

}
